package edu.pku.sei.mte.compositetrans.flow;

import java.util.Map;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import edu.pku.sei.mte.compositetrans.TController;
import edu.pku.sei.mte.compositetrans.TResult;
import edu.pku.sei.mte.compositetrans.agg.AGGController;
import edu.pku.sei.mte.compositetrans.atl.ATLController;
import edu.pku.sei.mte.compositetrans.configuration.TransDescriptor;
import edu.pku.sei.mte.compositetrans.mediniqvt.MediniQVTController;
import edu.pku.sei.mte.compositetrans.pkumt.PKUMTController;

public class TActionNode extends ActionNode<TController> {

	@Override
	public boolean execute() throws Exception{
		TResult res = action.transform();
		isSucceed = res.isSucceed;
		return isSucceed;
	}
	
	@Override
	public boolean isReady(){
		return true;
	}

	@Override
	public void load(Element root, Map<Integer, FlowNode> FlowNodesMap) {
		super.load(root, FlowNodesMap);
		Element e = null;
		NodeList nl = root.getChildNodes();
		for(int i=0;i<nl.getLength();i++){
			Node n = nl.item(i);
			if(n.getNodeType()!=Node.ELEMENT_NODE)
				continue;
			if(!n.getNodeName().equals(TransDescriptor.TRANS_CONFIG))
				continue;
			e = (Element) n;
		}
		if(e != null){
			if(root.getAttribute("engine").equals("agg"))
				action = new AGGController(e);
			else if(root.getAttribute("engine").equals("atl"))
				action = new ATLController(e);
			else if(root.getAttribute("engine").equals("mediniqvt"))
				action = new MediniQVTController(e);
			else if(root.getAttribute("engine").equals("pkumt"))
				action = new PKUMTController(e);
		}
	}
}
